#include "FPS.h"

extern void errorMessage(WCHAR* str);

#pragma warning(push)
#pragma warning(disable:4996)
CFps::CFps():FPS(60),fps(0),last_second(0),frames_accum(0),x(400),y(0)
{
	myFont = al_load_ttf_font("C:\\WINDOWS\\Fonts\\MSYH.TTF", 20, 0);
	if (!myFont)
	{
		errorMessage(L"can't open the MSYH.ttf");
	}
}

CFps::~CFps()
{
	al_destroy_font(myFont);
}

void CFps::update()
{
	double t = al_get_time();
	if (t >= last_second + 1) {
		fps = frames_accum / (t - last_second);
		frames_accum = 0;
		last_second = t;
	}
	frames_accum++;
}

void CFps::draw()
{ 
	sprintf(message, "%.2lf", fps);
	al_draw_text(myFont, al_map_rgb(255, 255, 255), x, y, 0, message);
}
#pragma warning(pop)